package org.acy.file.util;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class HttpUtil {

    public static byte[] read(String url) throws Exception {
        // 创建OkHttpClient实例
        OkHttpClient client = new OkHttpClient();

        // 创建一个Request对象
        Request request = new Request.Builder()
                .url(url) // 替换为你的PDF文件URL
                .build();

        // 获取Response对象
        Response response = client.newCall(request).execute();

        // 检查请求是否成功
        if (response.isSuccessful()) {
            // 获取PDF数据
            byte[] pdfBytes = response.body().bytes();
            // 处理PDF数据，例如保存到文件或显示
            response.close();
            return pdfBytes;
        } else {
            throw new RuntimeException("获取文件异常");
        }

    }
}
